/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.tbp.gui.table;

import br.com.tbp.model.domain.Empresa;
import br.com.tbp.utils.ImageUtils;
import java.util.ArrayList;
import java.util.List;
import javax.swing.Icon;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Diego
 */
public class EmpresasTableModel extends AbstractTableModel {

    private List<Empresa> lista;

    public EmpresasTableModel(List<Empresa> lista) {
        this.lista = lista;
    }

    public EmpresasTableModel() {
    }

    public int getRowCount() {
        return lista.size();
    }

    public int getColumnCount() {
        return 7;
    }

    @Override
    public Class<?> getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case 0:
                return Long.class;
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
                return String.class;
            case 6:
                return Boolean.class;
        }
        return Object.class;
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "ID empresa";
            case 1:
                return "Nome";
            case 2:
                return "CNPJ";
            case 3:
                return "Telefone";
            case 4:
                return "e-mail";
            case 5:
                return "Representante";
            case 6:
                return "Ativa?";
        }
        return null;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        Empresa p = this.getEmpresa(rowIndex);
        if (p != null) {
            switch (columnIndex) {
                case 0:
                    return p.getId();
                case 1:
                    return p.getNomeFantasia();
                case 2:
                    return p.getCnpj();
                case 3:
                    return p.getTelefone();
                case 4:
                    return p.getEmail();
                case 5:
                    return p.getRepresentante();
                case 6:
                    return p.isAtiva();
            }
        }
        return null;
    }

    public Empresa getEmpresa(int row) {
        if (row >= 0) {
            return lista.get(row);
        }
        return null;
    }

    public boolean removeEmpresa(Empresa c) {
        if (lista.remove(c)) {
            fireTableDataChanged();
            return true;
        }
        return false;
    }

    public List<Empresa> getListaDeItens() {
        return new ArrayList<Empresa>(lista);
    }

    public void setData(List<Empresa> data) {
        this.lista = data;
        fireTableDataChanged();
    }
}
